package org.linlinjava.litemall.admin.service;

import org.linlinjava.litemall.db.domain.LitemallUser;
import org.linlinjava.litemall.db.domain.PiccNurse;
import org.linlinjava.litemall.db.service.LitemallUserService;
import org.linlinjava.litemall.db.service.PiccNurseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class AdminPiccNurseService {
    @Autowired
    PiccNurseService piccNurseService;

    @Autowired
    LitemallUserService litemallUserService;

    public PiccNurse add(PiccNurse nurse){
        if(nurse.getId() == null) {
            //id是-1，则要insert
            piccNurseService.add(nurse);
        }
        else {
            //id有值，则更新
            piccNurseService.update(nurse);

            LitemallUser user = litemallUserService.findById(nurse.getUserId());
            user.setRole("nurse");
            litemallUserService.updateById(user);
        }
        return nurse;
    }
}
